# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library", "iree_gentbl_cc_library", "iree_tablegen_doc", "iree_td_library")
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

exports_files(["UtilBase.td"])

iree_td_library(
    name = "td_files",
    srcs = enforce_glob(
        [
            "UtilAttrs.td",
            "UtilBase.td",
            "UtilInterfaces.td",
            "UtilOps.td",
            "UtilTypes.td",
        ],
        include = ["*.td"],
    ),
    deps = [
        "@llvm-project//mlir:BuiltinDialectTdFiles",
        "@llvm-project//mlir:CallInterfacesTdFiles",
        "@llvm-project//mlir:ControlFlowInterfacesTdFiles",
        "@llvm-project//mlir:FunctionInterfacesTdFiles",
        "@llvm-project//mlir:InferIntRangeInterfaceTdFiles",
        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:SideEffectInterfacesTdFiles",
        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
    ],
)

iree_compiler_cc_library(
    name = "IR",
    srcs = [
        "ClosureOpUtils.cpp",
        "UtilAttrs.cpp",
        "UtilDialect.cpp",
        "UtilOpFolders.cpp",
        "UtilOps.cpp",
        "UtilTypes.cpp",
    ],
    hdrs = [
        "ClosureOpUtils.h",
        "UtilDialect.h",
        "UtilOps.h",
        "UtilTraits.h",
        "UtilTypes.h",
    ],
    textual_hdrs = [
        "UtilAttrs.cpp.inc",
        "UtilAttrs.h.inc",
        "UtilAttrInterfaces.cpp.inc",
        "UtilAttrInterfaces.h.inc",
        "UtilEnums.cpp.inc",
        "UtilEnums.h.inc",
        "UtilOpInterfaces.cpp.inc",
        "UtilOpInterfaces.h.inc",
        "UtilOps.cpp.inc",
        "UtilOps.h.inc",
        "UtilTypeInterfaces.cpp.inc",
        "UtilTypeInterfaces.h.inc",
        "UtilTypes.cpp.inc",
        "UtilTypes.h.inc",
    ],
    deps = [
        ":UtilAttrsGen",
        ":UtilInterfacesGen",
        ":UtilOpsGen",
        ":UtilTypesGen",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:CastInterfaces",
        "@llvm-project//mlir:ControlFlowDialect",
        "@llvm-project//mlir:ControlFlowInterfaces",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:InliningUtils",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
        "@llvm-project//mlir:UBDialect",
        "@llvm-project//mlir:ViewLikeInterface",
    ],
)

iree_gentbl_cc_library(
    name = "UtilAttrsGen",
    tbl_outs = [
        (
            ["--gen-attrdef-decls"],
            "UtilAttrs.h.inc",
        ),
        (
            ["--gen-attrdef-defs"],
            "UtilAttrs.cpp.inc",
        ),
        (
            ["--gen-enum-decls"],
            "UtilEnums.h.inc",
        ),
        (
            ["--gen-enum-defs"],
            "UtilEnums.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "UtilAttrs.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "UtilInterfacesGen",
    tbl_outs = [
        (
            ["--gen-attr-interface-decls"],
            "UtilAttrInterfaces.h.inc",
        ),
        (
            ["--gen-attr-interface-defs"],
            "UtilAttrInterfaces.cpp.inc",
        ),
        (
            ["--gen-op-interface-decls"],
            "UtilOpInterfaces.h.inc",
        ),
        (
            ["--gen-op-interface-defs"],
            "UtilOpInterfaces.cpp.inc",
        ),
        (
            ["--gen-type-interface-decls"],
            "UtilTypeInterfaces.h.inc",
        ),
        (
            ["--gen-type-interface-defs"],
            "UtilTypeInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "UtilInterfaces.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "UtilOpsGen",
    tbl_outs = [
        (
            ["--gen-op-decls"],
            "UtilOps.h.inc",
        ),
        (
            ["--gen-op-defs"],
            "UtilOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "UtilOps.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "UtilTypesGen",
    tbl_outs = [
        (
            ["--gen-typedef-decls"],
            "UtilTypes.h.inc",
        ),
        (
            ["--gen-typedef-defs"],
            "UtilTypes.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "UtilTypes.td",
    deps = [":td_files"],
)

iree_tablegen_doc(
    name = "UtilDialectDocGen",
    category = "Dialects",
    tbl_outs = [
        (
            [
                "--gen-dialect-doc",
                "--dialect=util",
            ],
            "UtilDialect.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "UtilOps.td",
    deps = [":td_files"],
)
